<template>
  <Tooltip
    title="AI选股"
    placement="bottom"
    :mouseEnterDelay="0.5"
    @click="handleToAIChat"
  >
    
      <Icon icon="ant-design:reddit-outlined" />
    
  </Tooltip>
</template>
<script lang="ts">
  import { defineComponent, onMounted, ref } from 'vue';
  import { Tooltip, Badge } from 'ant-design-vue';
  import Icon from '/@/components/Icon';

    import { useUserStore } from '/@/store/modules/user';

  import { useRouter } from 'vue-router';

  export default defineComponent({
    name: 'chatai',
    components: { Icon, Tooltip, Badge },

    setup() {
      const userStore = useUserStore();
      const { push } = useRouter();
      var cozeWebSDK;
var a= userStore.getUserInfo||{};
//alert(a.userCode)
      onMounted(async () => {

      const script = document.createElement('script');
      script.src = 'https://lf-cdn.coze.cn/obj/unpkg/flow-platform/chat-app-sdk/1.1.0-beta.0/libs/cn/index.js'; // 替换为你的外部JS文件URL
      script.onload = () => {
        // 文件加载完毕后的操作
        cozeWebSDK=new CozeWebSDK.WebChatClient({
            config: {
              bot_id: '7455694818217017353',
            },
            auth:  {
    type: 'token',
    token: 'pat_ekTurjKKAM3gpgEV4WGkz72BA7koVIwXg2SDQDQPTSLcYRMbvncEXuA8QCaKz4jt',
    onRefreshToken: async () => 'pat_ekTurjKKAM3gpgEV4WGkz72BA7koVIwXg2SDQDQPTSLcYRMbvncEXuA8QCaKz4jt',
  },
            userInfo: {
      id: a.userCode,
      url: 'https://lf-coze-web-cdn.coze.cn/obj/coze-web-cn/obric/coze/favicon.1970.png',
      nickname: a.userName,
    },
            ui:{
              asstBtn: {
          isNeed: false,
      },
            },
            componentProps: {
              title: 'DEECP选股助手',
            },
          });

          cozeWebSDK.addOnBeforeMessageSend();
      };
      document.head.appendChild(script);
      

      
    });
      function handleToAIChat() {
        
        console.log(a.userName)
        cozeWebSDK.showChatBot();
      }

      return {
      
        handleToAIChat,
      };
    },
  });
</script>
